package com.web.servlet;

import com.utils.CodeUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/code")
public class CodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用验证码工具类获得图片和验证码
        String checkCode = CodeUtil.getCheckCode();
        CodeUtil.outputImage(response.getOutputStream());
        //将验证码存储到session中去
        HttpSession session = request.getSession();
        session.setAttribute("code",checkCode);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
